<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="600"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form :model="form" ref="dialogForm" label-width="65px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="产品">
            <el-input v-model="form.material.spec" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="颜色" prop="billdate">
            <el-date-picker v-model="form.color_name" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="缸号">
            <el-input v-model="form.dyelot" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="流转号" prop="batchno">
            <el-date-picker v-model="form.batchno" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="匹" prop="auxiliary_quantity">
            <el-date-picker v-model="form.auxiliary_quantity" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="数" prop="quantity">
            <el-input v-model="form.quantity" disabled></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <sc-VxeTable
      :tablecode="'pro_outsourcing_delivery_pack'"
      :data="form.packs"
      :gridOps="{ height: 300 }"
      ref="subbe"
    >
    </sc-VxeTable>
    <!-- </sc-water-mark> -->
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>
<script>
// import XEUtils from "xe-utils";
export default {
  emits: ["success", "closed"],
  components: {},
  data() {
    return {
      mode: "add",
      form: {
        material: {},
        packs: [],
      },
      gridEvts: {},
      titleMap: {
        add: "新增",
        edit: "编辑",
      },
      visible: false,
      isSaveing: false,
      refdata: null,
    };
  },
  mounted() {},
  methods: {
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },

    //表单提交方法
    submit() {
      let quantity = 0,
        auxiliary_quantity = 0;
      this.form.packs.map((v) => {
        quantity += parseFloat(v.quantity);
        auxiliary_quantity += parseFloat(v.auxiliary_quantity);
      });
      this.resform.quantity = quantity;
      this.resform.auxiliary_quantity = auxiliary_quantity;
      this.resform.packs = this.form.packs;
      this.$emit("success");
      this.visible = false;
    },
    //表单注入数据
    setData(data) {
      this.resform = data;
      Object.assign(this.form, this.$TOOL.objCopy(data));
      return this;
    },
  },
};
</script>
